home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NetNews Offline 2
/
NetNews Offline Volume 2.iso
/
news
/
comp
/
std
/
c
/
529
< prev
next >
Wrap
Internet Message Format
|
1996-08-06
|
3KB
Path: newshost.lanl.gov!tanmoy
From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
Newsgroups: comp.std.c
Subject: Re: Bit-field sizes
Date: 06 Mar 1996 15:45:02 GMT
Organization: Los Alamos National Laboratory
Message-ID: <TANMOY.96Mar6084502@qcd.lanl.gov>
References: <nzRPxQ9ytZZA084yn@csn.net>
NNTP-Posting-Host: qcd.lanl.gov
Mime-Version: 1.0
Content-Type: text
In-reply-to: thads@csn.net's message of 5 Mar 1996 23:49:35 -0700
In article <nzRPxQ9ytZZA084yn@csn.net>
thads@csn.net (Thad Smith) writes:
TS: Can the size of a bit-field, measured in bits, exceed the size of an
TS: int? The description of bit-fields describes it as an integral
TS: type with a (programmer-)specified number of bits, not specifically
TS: constrained in size. ANSI Classic section 3.2.1.1 says, however, that
TS: bit-fields are promoted to either int or unsigned int. This would
TS: seem to prohibit promoting a large bit-field to a long. If so, why
TS: was this constraint imposed?
6.5.2.1 constraints: The expression that specifies the width of a
bit-field ... shall not exceed the number of bits in an ordinary
object of compatible type.
So, the number of bits cannot exceed the number of bits in an int or
unsigned int.
TS:
TS: Secondly, is the storage unit within which bit-fields are allocated
TS: constrained to be a single size or can it vary, depending on the size
TS: of the bit fields? I see nothing in the standard prohibiting
TS: different size storage units for bit-fields. Also bit-fields are
Neither do I.
TS: explicitly allowed to span multiple storage units, at least if the
TS: bit-field is not the first in a structure (the use of the word "may"
TS: makes the requirement for the first bit-field ambiguous with regard to
TS: storage in a single unit).
Depends on whether an addressable storage unit has to occur in
multiples of bytes. (The standard says that bytes are addressable
storage units, but not the converse. If addressable means that & can
be applied to it, again, the smallest addressable unit is a byte). If
it has to, then a width 4 bit field followed by width 2 bit field must
both belong to the same addressable storage unit, and neither can span
storage units.
TS:
TS: If different size storage units are allowed or any bit-field is
TS: allowed to span multiple units, the size of a struct containing
TS: bit-fields might be 1 byte, while bit-fields could be allocated up to
TS: the size (in bits) of ints, possibly four bytes in a particular
TS: implementation, by choosing larger storage units for larger
TS: bit-fields.
I guess so.
TS:
TS: Is anyone aware of an implementation using bit-field storage units
TS: smaller than int?
Cheers
Tanmoy
--
tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]